package com.yyc.system.controller;
import com.yyc.core.Result;
import com.yyc.core.ResultGenerator;
import com.yyc.system.model.TCourseUser;
import com.yyc.system.service.ITCourseUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* Created by yyc on 2019/01/07.
*/
@RestController
@RequestMapping("/t/course/user")
public class TCourseUserController {
    @Autowired
    private ITCourseUserService tCourseUserService;

    @RequestMapping("/add")
    public Result add(@RequestBody TCourseUser tCourseUser) {
        tCourseUserService.save(tCourseUser);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestParam String ids) {
        tCourseUserService.deleteByIds(ids);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody TCourseUser tCourseUser) {
        tCourseUserService.update(tCourseUser);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        TCourseUser tCourseUser = tCourseUserService.findById(id);
        return ResultGenerator.genSuccessResult(tCourseUser);
    }

    @RequestMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<TCourseUser> list = tCourseUserService.findAll();
        PageInfo<TCourseUser> pageInfo = new PageInfo<TCourseUser>(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
    
    //*********************************************************************
    //选课
    @RequestMapping("/chooseCourse")
    public Result chooseCourse(@RequestBody List<TCourseUser> courseUser) {
    	tCourseUserService.saveList(courseUser);
		return ResultGenerator.genSuccessResult();
    	
    }
    
    //选课或批量添加课程
    @RequestMapping("/addList")
    public Result addList(@RequestBody List<TCourseUser> courseUserList) {
    	tCourseUserService.saveList(courseUserList);
    	return ResultGenerator.genSuccessResult();
    }
}
